﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.Mvc;

namespace AugustaDevelopersGuild.Models
{
    public class Meeting
    {
        [HiddenInput(DisplayValue = false)]
        public int MeetingID { get; set; }

        [Required(ErrorMessage = "Event Date is required")]
        [Display(Name = "Event Date")]
        public DateTime EventDate { get; set; }

        [Required(ErrorMessage = "Speaker is required")]
        [StringLength(50, ErrorMessage = "Speaker may not be longer than 50 characters")]
        public string Speaker { get; set; }

        [DataType(DataType.MultilineText)]
        public string Bio { get; set; }

        [Required(ErrorMessage = "Topic is required")]
        [StringLength(256, ErrorMessage = "Topic may not be longer than 256 characters")]
        public string Topic { get; set; }

        [DataType(DataType.MultilineText)]
        public string Abstract { get; set; }

        public virtual ICollection<Rsvp> Rsvps { get; set; }

        public bool IsUserRegistered(string userName)
        {
            return Rsvps.Any(r => r.AttendeeNameId == userName || (r.AttendeeNameId == null && r.AttendeeName == userName));
        }
    }
}